#include <stdio.h>
#include <malloc.h>

#define EDEN_SIZE 1024 * 1024 * 16






int main() {
    //堆区初始化大小16M，实际开辟 16 * 3 48M
    //其中16M为EDEN 32M为堆区
    char* head = malloc(EDEN_SIZE * 3);
    printf("申请空间位置%x ~ %x\n",&head,(&head + (EDEN_SIZE * 3)));
    //年轻代设计分配
    int yong_begin = &head ;
    int yong_end = &head + EDEN_SIZE;


    int eden_begin = &yong_begin;
    int eden_end = &yong_begin + (int)(EDEN_SIZE * 0.8-1);
    //survivor区分配
    int survivor1_begin =&yong_begin + (int)(EDEN_SIZE * 0.8);
    int survivor1_end = &yong_begin + (int)(EDEN_SIZE * 0.9 - 1);
    int survivor2_begin =&yong_begin + (int)(EDEN_SIZE * 0.9);
    int survivor2_end =&yong_begin + (int)(EDEN_SIZE);

    //老年代设计
    int old_begin = &head + EDEN_SIZE;
    int old_end = old_begin + EDEN_SIZE * 3;

    printf("eden空间分配区间%x ~ %x\n",eden_begin,eden_end);
    printf("survivor1空间分配区间%x ~ %x\n",survivor1_begin,survivor1_end);
    printf("survivor2空间分配区间%x ~ %x\n",survivor2_begin,survivor2_end);
    printf("eden空间分配区间%x ~ %x\n",old_begin,old_end);

    //java代码：int i = 10;
    //指针标记
    char* index = &head;
    printf("当前地址%x\n",index);

    int i = 20;
    //length 4 value 20
    char* val = 20;
    int length = 4;

    char* v1Index = index;

    *index = val;
    index += length;
    printf("1当前分配后位置%x\n",index);

    char* v2Index = index;
    char* val2 = 30;
    int length2 = 4;
    *index = val2;
    index += length2;
    printf("2当前分配后位置%x\n",index);

    char value = *v1Index;
    printf("value:%d\n",value);

    int value2 = *v2Index;
    printf("value2:%d\n",value2);

    return 0;
}




